package com.yunmang.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.yunmang.R;
import com.yunmang.entity.ParameterEntity.SignBean;
import com.yunmang.utils.ViewHolderUtils;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by Administrator on 2017/5/10.
 */
public class NosendAdapter extends BaseAdapter{
    private Context context;
    private List<SignBean.ModelBean.ItemsBean> dataList;
    public NosendAdapter(Context context,List<SignBean.ModelBean.ItemsBean> dataList){
        this.context=context;
        this.dataList=dataList;
    }
    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        SignBean.ModelBean.ItemsBean itemsBean = dataList.get(i);
        if(convertView==null)
            convertView=View.inflate(context, R.layout.item_sign, null);
        TextView tv_hdbh = ViewHolderUtils.get(convertView, R.id.tv_hdbh);
        TextView tv_ship_name = ViewHolderUtils.get(convertView, R.id.tv_ship_name);
        TextView tv_goods_name = ViewHolderUtils.get(convertView, R.id.tv_goods_name);
        TextView tv_freight = ViewHolderUtils.get(convertView, R.id.tv_freight);
        TextView tv_collect_money = ViewHolderUtils.get(convertView, R.id.tv_collect_money);
        TextView tv_style = ViewHolderUtils.get(convertView, R.id.tv_style);
        TextView tv_sum = ViewHolderUtils.get(convertView, R.id.tv_sum);
        ImageView iv_takemethod = ViewHolderUtils.get(convertView, R.id.iv_takemethod);
        TextView tv_sign = ViewHolderUtils.get(convertView, R.id.tv_sign);

        Button btn_sign = ViewHolderUtils.get(convertView, R.id.btn_sign);
        tv_hdbh.setText(itemsBean.getHdbh());
        tv_ship_name.setText(itemsBean.getShipper());
        tv_goods_name.setText(itemsBean.getGoodsName());
        tv_freight.setText(itemsBean.getTransportCost()+"");
        tv_collect_money.setText(itemsBean.getGoodsCost()+"");
        tv_style.setText(itemsBean.getTakeMethod());
        if(itemsBean.getTakeMethod().trim().equals("自提")){
            iv_takemethod.setImageResource(R.mipmap.icon_yg_ziti);
            btn_sign.setText("签收");
            tv_sign.setText("签收");
            tv_sign.setBackgroundResource(R.drawable.bg_edit);
        }else{
            int status=itemsBean.getStatus();
            iv_takemethod.setImageResource(R.mipmap.icon_yg_song);
            if(status==5){
                btn_sign.setText("签收");
                tv_sign.setText("签收");
            }else{
                btn_sign.setText("派送");
                tv_sign.setText("派送");
            }

            tv_sign.setBackgroundResource(R.drawable.bg_del);
        }
        return convertView;
    }
    public void refresh(List<SignBean.ModelBean.ItemsBean> dataList){
        this.dataList=dataList;
        notifyDataSetChanged();
    }
}
